﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using DAO;
using System.Data;

namespace BUS
{
    public class LoaiMonBUS
    {
        public static List<LoaimonDTO> Listloaimon()
        {
            List<LoaimonDTO> lstloaimon = null;
            DataTable dt = LoaiMonDAO.ListLoaimon();
            if (dt != null)
            {
                lstloaimon = new List<LoaimonDTO>();
                foreach (DataRow dr in dt.Rows)
                {
                    LoaimonDTO loai = new LoaimonDTO();
                    loai.Maloai=int.Parse(dr["MALOAI"].ToString());
                    loai.Tenloai = dr["TENLOAI"].ToString();
                    lstloaimon.Add(loai);
                }
            }
            return lstloaimon;

        }

        public static bool Themmon(LoaimonDTO mon)
        {
            int kt = LoaiMonDAO.ThemLoaimon(mon);
            if (kt > 0)
            { return true; }
            return false;
        }

        public static bool Xoamon(int maloaimon)
        {
            int kt = LoaiMonDAO.XoaMon(maloaimon);
            if (kt > 0)
            { return true; }
            return false;
        }

        public static string TenLoai(int maloai)
        {
            DataTable dt = LoaiMonDAO.Tenloai(maloai);
            string tenloai="";
            if (dt != null)
            {
                tenloai = dt.Rows[0]["TENLOAI"].ToString();
            }
            return tenloai;
        }
    }
}
